class Ticket < ActiveRecord::Base
  acts_as_nested_set

  validates_presence_of :title, :department_id
  validates_presence_of :question, :on =>  :create

  has_many :workflows, :include => :status

 # has_many :statuses, :through => :workflows

  belongs_to :department
  belongs_to :client
  belongs_to :user


  after_create :set_status_for_ticket

  # set status for new create ticket
  def set_status_for_ticket
    def_status = Trackingsystem::Application.config.base_status_for_ticket
    self.workflows.build({status_id: def_status}).save
  end
end
